import reqwest from "reqwest";
import {message} from "antd";

/**
 * 上传文件
 * @param uri
 * @param data 文件数据
 * @returns {Promise<unknown>}
 */
function uploadFile(
    uri = {
        tableName: "",
        fieldName: "",
        ownerId: ""
    }, data) {
    let url = `http://localhost:8080/attachment/upload?tableName=${uri.tableName}&fieldName=${uri.fieldName}&ownerId=${uri.ownerId}`;
    return new Promise((resolve, reject) => {
        reqwest({
            url,
            method: 'post',
            processData: false,
            data,
            success: (resp) => {
                message.success('上传成功').then(r => {
                    resolve(resp);
                });
            },
            error: (resp) => {
                message.error('上传失败').then(r => {
                    reject(resp);
                });
            },
        });
    });
}

export {uploadFile};